<template>
  <div>
    <el-container>
      <img src="../assets/3.jpeg" alt="" class="imges" />
      <el-header>怡红院管理后台</el-header>
      <p id="name">{{ userinfo.username }}</p>
      <p class="out" @click="outusers">退出登录</p>
      <el-container>
        <el-aside width="200px" id="cebian">
          <el-menu
            default-active="2"
            class="el-menu-vertical-demo"
            :unique-opened="true"
            :router="true"
          >
            <el-submenu
              :index="item.path"
              v-for="(item, index) in meunsdata"
              :key="index"
            >
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{ item.authName }}</span>
              </template>
              <el-menu-item-group>
                <el-menu-item
                  :index="val.path"
                  v-for="(val, key) in item.children"
                  :key="key"
                  >{{ val.authName }}</el-menu-item
                >
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data() {
    return {
      userinfo: {},
      meunsdata: [],
    };
  },
  methods: {
    //退出登录
    outusers() {
      alert("确认退出吗？傻逼");
      localStorage.removeItem("userinfo");
      //退出登录成功跳转页面
      this.$router.push({ path: "/login" });
    },
  },

  async mounted() {
    //获取用户数据，转换以获取本地储存的方式来获取到userinfo，在转换成对象的形式赋值给userinfo
    this.userinfo = JSON.parse(localStorage.getItem("userinfo"));

    //获取侧边栏的数据
    const { data } = await this.$qiuzi.get("/menus");
    console.log(data.data);
    if (data.meta.status == 200) {
      this.meunsdata = data.data;
    } else {
      this.$message.error(data.meta.msg);
    }
  },
};
</script>

<style>
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  line-height: 160px;
}

#name {
  position: absolute;
  right: 40px;
  top: 15px;
}
#cebian {
  height: 835px;
}
.imges {
  position: absolute;
  width: 50px;
  left: 100px;
  top: 13px;
  border-radius: 30px;
}

.out {
  position: absolute;
  top: 60px;
  right: 25px;
  background: greenyellow;
}
</style>
